import json
import os
import sys

import facade
import parsel
from xjlibrary.our_file_dir import BaseDir

curPath = BaseDir.get_file_dir_absolute(__file__)
configfile = BaseDir.get_new_path(curPath, "db.ini")
topPath = BaseDir.get_upper_dir(curPath, -2)
sPath = BaseDir.get_new_path(topPath, "download", "adks_cqjd", "download", "cover")


class ParaHome(object):
    def __init__(self):
        self.logger = facade.get_streamlogger()
        self.mysqlutiles = facade.MysqlUtiles(configfile, "db", logger=self.logger)
        self.input1 = set()
        self.input2 = set()

    def select(self):
        sql = "SELECT rawid from article"
        rows = self.mysqlutiles.SelectFromDB(sql)
        for row in rows:
            self.input1.add(row[0])

        for path, dirNames, fileNames in os.walk(sPath, topdown=True):
            # 获取当前目录的所有文件
            for fileName in fileNames:
                i = fileName.replace(".jpg","")
                self.input2.add(i)

        print(self.input1 - self.input2)


if __name__ == "__main__":
    para = ParaHome()
    para.select()